var FormUtil={};

import {I18Parse} from '@lowcode/jpaas-common-lib';
import formBoListDialog from '../../../../locales/lang/impl/form/formBoListDialogLang';
let lang = formBoListDialog;

/**
 * 构建表单模板。
 * @param tmp
 * @returns {string|*}
 */
FormUtil.getTemplate=function (json) {
  let metadata=json.metadata;
  if(typeof metadata =="string"){
      metadata=JSON.parse(metadata);
  }

  let forceRender= true;
  if(metadata.formAllConfig )  {
      forceRender= metadata.formAllConfig.forceRender;
      if(forceRender==undefined){
          forceRender=true;
      }
  }

  var tmp=json.template;
  var wizard=json.wizard;


  var aryTmp= JSON.parse(tmp);
  if(aryTmp.length==1){
    return aryTmp[0].content;
  }
  else{
    var ary = [];
    var _len = aryTmp.length ;
    if(wizard){
      //fromTabActive ,changeTab，readonly，tabPrev，tabNext在 表单设计代码的rxform.js中;
      ary.push('<a-tabs :activeKey= "fromTabActive" ref="fromTab" @change="changeTab">');
    }else {
      ary.push('<a-tabs defaultActiveKey="tab0" ref="fromTab" @change="changeTab">');
    }
    for (var i = 0; i < _len; i++) {
      var tab = aryTmp[i];
      if(wizard){
        ary.push(`<a-tab-pane tab="${tab.title}" key="tab${i}" :disabled="!readonly" :forceRender="${forceRender}">
            <div id="fromTab${i}">
                 ${tab.content}
                 <div style="padding:10px;text-align:center;">
                   <a-button type="primary" @click="tabPrev(${i},${_len})"  v-if="${ i == 0 ? false:true } && !readonly" style="margin-right:6px;" >${I18Parse.getI18Val(lang,'list.previous','上一步')}</a-button>				            
                   <a-button type="primary" @click="tabNext(${i},${_len})"  v-if="${ i == _len - 1 ? false:true } && !readonly" >${I18Parse.getI18Val(lang,'list.nextStep','下一步')}</a-button>			            
                 </div>
           </div>
          </a-tab-pane>`);
      }else{
        ary.push(`<a-tab-pane tab="${tab.title}" key="tab${i}" :forceRender="${forceRender}">${tab.content}</a-tab-pane>`);
      }
    }
    ary.push("</a-tabs>");
    return ary.join("");
  }
}


export default FormUtil;